import commonConstants from "@/common/commonConstants";
import MarkerManager from "../marker/MarkerManager";
import DefaultMonitor from "./DefualtMonitor";
import JBMonitor from "./JBMonitor";
import TroopListecner from "../troop/troopListecner";
import NormalTrackListencer from "../track/normalTrackListencer";
import {PlotFrankArrowMarker,GlobeCircleMarker} from "./linearplotting"

class MonitorManager{
  
    constructor(viewer,configs){
        this.curViewer = viewer;
        this.monitors = new Map();
        this.defaultMonitor = new DefaultMonitor(viewer);
        this.defaultMonitor.setManager(this);
        this.deployDefaultMonitor();

        this.markerManager = undefined;

        this.markerable  = true;
        this.measureable = false

        this._handlerConfigs(configs);

        //其他的实现监听器，也可以在这里初始化
        this._initDefaultMoinitor(viewer);
    }

    _handlerConfigs(configs){
        const _this = this;
        if(configs){
            configs.forEach(config => {
                if(config.getKey() == "markerable"){
                    _this.markerable = config.getValue();
                }
                //如果有其他的属性继续判断
                if(config.getKey() == "measureable"){
                    _this.measureable = config.getValue();
                }
            });
        }

    }
    
    _initDefaultMoinitor(v){
        const _this = this;

        //兵力
        _this.registerMonitor("troopMonitor",new TroopListecner(_this.curViewer));
        _this.registerMonitor("normalTrackMonitor",new NormalTrackListencer(_this.curViewer));
        //标绘的实现靠参数的控制
        if (_this.markerable){
            _this.registerMonitor(commonConstants.monitorKey.JB,new JBMonitor(_this.curViewer));
            // _this.registerMonitor("TextMarker",new TextMarker(curViewer));
            // _this.registerMonitor("communicationLineDrawer",new CommunicationLinkDrawer(curViewer));
            // _this.registerMonitor("PlotAttackArrowMarker",new PlotAttackArrowMarker(curViewer));
            // _this.registerMonitor("PlotTailCircleArrowMarker",new PlotTailCircleArrowMarker(curViewer));
            // _this.registerMonitor("PlotPincerArrowMarker",new PlotPincerArrowMarker(curViewer));
            // _this.registerMonitor("PlotStraightArrowMarker",new PlotStraightArrowMarker(curViewer));
            _this.registerMonitor(commonConstants.monitorKey.line.plotFrankArrow,new PlotFrankArrowMarker(_this.curViewer));
            _this.registerMonitor(commonConstants.monitorKey.line.globeCircle,new GlobeCircleMarker(_this.curViewer));
            // _this.registerMonitor("ConcentrateAreaMarker",new ConcentrateAreaMarker(curViewer));
            // _this.registerMonitor("DefenseLineMarker",new DefenseLineMarker(curViewer));
            // _this.registerMonitor("InfantryTankAttackFormationMarker",new InfantryTankAttackFormationMarker(curViewer));
            // _this.registerMonitor("OperationalBoundaryLineMarker",new OperationalBoundaryLineMarker(curViewer));
            // _this.registerMonitor("LandingLineMarker",new LandingLineMarker(curViewer));
            // _this.registerMonitor("RectangleMarker",new RectangleMarker(curViewer));
            // _this.registerMonitor("KeyPointMarker",new KeyPointMarker(curViewer));
            // _this.registerMonitor("PolylineMarker",new PolylineMarker(curViewer));
            // _this.registerMonitor("LandingShipAttackDirectionMarker",new LandingShipAttackDirectionMarker(curViewer));
        }
        if(_this.measureable){
            //测绘工具
            // _this.registerMonitor(CommonConstants.measureType.PointMeasure,new PointMeasure(curViewer));
            // _this.registerMonitor(CommonConstants.measureType.PolylineMeasure,new PolylineMeasure(curViewer));
            // _this.registerMonitor(CommonConstants.measureType.PolygonMeasure,new PolygonMeasure(curViewer));
        }
      
    }

    setCurMonitor(monitor){
        let _this = this;
        _this.deployMonitor(monitor);
    }

    /**
     * 
     * @param {MarkerManager} manager 
     */
    setMarkerManager(manager){
        const _this = this;
        _this.markerManager = manager;
    }
    /**
     * 
     * @returns {MarkerManager}
     */
    getMarkerManager(){
        const _this = this;
        return _this.markerManager;
    }

    deployDefaultMonitor() {
        let _this = this;
        _this.deployMonitor(_this.defaultMonitor);
    }
    deployMonitorByKey(regKey) {
        let _this = this;
        _this.deployMonitor(_this.monitors.get(regKey));
    }
    /**
     *
     * @return {null|DefaultMonitor}
     */
    getDefaultMonitor(){
        let _this = this;
        return _this.defaultMonitor;
    }
    deployMonitor(monitor) {
        let _this = this;
        if (_this.curMonitor){
            _this.curMonitor.setActive(false);
        }
        if (!monitor){
            monitor = _this.defaultMonitor;
        }
        monitor.setActive(true);
        monitor.deploy();
        _this.curMonitor = monitor;
    }
    /**
     *
     * @param key
     * @return {V}
     */
    getMonitorByKey(key) {
        let _this = this;
        return _this.monitors.get(key);
    }
    logoutMonitor(reg_key) {
        let _this = this;
        _this.monitors.delete(reg_key);
    }
    registerMonitor(reg_key, monitor) {
        let _this = this;
        monitor.setManager(_this);
        _this.monitors.set(reg_key,monitor);
    }
};

export default MonitorManager;